<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <title>给多个点添加信息窗体</title>
  <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
  <script type="text/javascript"
          src="https://webapi.amap.com/maps?v=2.0&key=19e2eebff55e44849ae28a8a246e3475"></script>
  <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
  <style>
    html, body, #container {
      height: 100%;
      width: 100%;
    }

    .content-window-card {
      position: relative;
      box-shadow: none;
      bottom: 0;
      left: 0;
      width: auto;
      padding: 0;
    }

    .content-window-card p {
      height: 2rem;
    }

    .custom-info {
      border: solid 1px silver;
    }

    div.info-top {
      position: relative;
      background: none repeat scroll 0 0 #F9F9F9;
      border-bottom: 1px solid #CCC;
      border-radius: 5px 5px 0 0;
    }

    div.info-top div {
      display: inline-block;
      color: #333333;
      font-size: 14px;
      font-weight: bold;
      line-height: 31px;
      padding: 0 10px;
    }

    div.info-top img {
      position: absolute;
      top: 10px;
      right: 10px;
      transition-duration: 0.25s;
    }

    div.info-top img:hover {
      box-shadow: 0px 0px 5px #000;
    }

    div.info-middle {
      font-size: 12px;
      padding: 10px 6px;
      line-height: 20px;
    }

    div.info-bottom {
      height: 0px;
      width: 100%;
      clear: both;
      text-align: center;
    }

    div.info-bottom img {
      position: relative;
      z-index: 104;
    }

    span {
      margin-left: 5px;
      font-size: 11px;
    }

    .info-middle img {
      float: left;
      margin-right: 6px;
    }
  </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
  //初始化地图对象，加载地图
  var map = new AMap.Map("container", {
    resizeEnable: true,
    center: [116.481181, 39.989792],
    zoom: 16
  });

  let lnglats = [
    [116.368904, 39.923423],
    [116.382122, 39.921176],
    [116.387271, 39.922501],
    [116.398258, 39.914600]
  ];
  //实例化信息窗体
  let title = '方恒假日酒店<span style="font-size:11px;color:#F00;">价格:318</span>',
          content = [];
  content.push("<img src='https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png'>地址：北京市朝阳区阜通东大街6号院3号楼东北8.3公里");
  content.push("电话：010-64733333");
  content.push("<a href='https://ditu.amap.com/detail/B000A8URXB?citycode=110105'>详细信息</a>");
  let infoWindow = new AMap.InfoWindow({
    isCustom: true,  //使用自定义窗体
    content: createInfoWindow(title, content.join("<br/>")),
    offset: new AMap.Pixel(16, -45)
  });
  //构建自定义信息窗体
  function createInfoWindow(title, content) {
    let info = document.createElement("div");
    info.className = "custom-info input-card content-window-card";

    //可以通过下面的方式修改自定义窗体的宽高
    info.style.width = "400px";
    // 定义顶部标题
    let top = document.createElement("div");
    let titleD = document.createElement("div");
    let closeX = document.createElement("img");
    top.className = "info-top";
    titleD.innerHTML = title;
    closeX.src = "https://webapi.amap.com/images/close2.gif";
    closeX.onclick = closeInfoWindow;

    top.appendChild(titleD);
    top.appendChild(closeX);
    info.appendChild(top);

    // 定义中部内容
    let middle = document.createElement("div");
    middle.className = "info-middle";
    middle.style.backgroundColor = 'white';
    middle.innerHTML = content;
    info.appendChild(middle);

    // 定义底部内容
    let bottom = document.createElement("div");
    bottom.className = "info-bottom";
    bottom.style.position = 'relative';
    bottom.style.top = '0px';
    bottom.style.margin = '0 auto';
    let sharp = document.createElement("img");
    sharp.src = "https://webapi.amap.com/images/sharp.png";
    bottom.appendChild(sharp);
    info.appendChild(bottom);
    return info;
  }


  for (let i = 0, marker; i < lnglats.length; i++) {
    let marker = new AMap.Marker({
      position: lnglats[i],
      map: map
    });
    // marker.content = '我是第' + (i + 1) + '个Marker';
    marker.on('click', function () {
      infoWindow.open(map, marker.getPosition());
    });    // marker.emit('click', {target: marker});
  }
  function markerClick(e) {
    infoWindow.setContent(e.target.content);
    infoWindow.open(map, e.target.getPosition());
  }
  map.setFitView();

  //关闭信息窗体
  function closeInfoWindow() {
    map.clearInfoWindow();
  }
</script>
</body>
</html>
